﻿using System;
using System.Windows.Data;

namespace TCC.ControleFluxoDeCaixa.Apresentacao.ResourcesDictionaries.Converters
{
    public class EnumMatchToBooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return Binding.DoNothing;

            if (value is bool)
            {
                //value = (bool) value ? ViewsModels.Questionarios.SimNaoBoolean.Sim : ViewsModels.Questionarios.SimNaoBoolean.Nao;                
                return value;
            }

            return ((Enum) value).HasFlag((Enum) parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            if (targetType == null) throw new ArgumentNullException("targetType");
            if (targetType == typeof(bool?))
            {
                return value.Equals(true); // Binding.DoNothing;
            }
            
            return value.Equals(true) ? parameter : Binding.DoNothing;
        }

    }
}